import java.util.ArrayList;
import java.util.List;

/**
 * @author SaoE
 * @date 2025/2/24 11:56
 */
public class _46 {
    List<List<Integer>> res = new ArrayList<>();
    public List<List<Integer>> permute(int[] nums) {
        List<Integer> temp = new ArrayList<>();
        backTrace(nums, temp);
        return res;
    }
    public void backTrace(int[] nums, List<Integer> list){
        if(list.size() == nums.length){
            res.add(new ArrayList<>(list));
            return;
        }
        for(int j = 0; j < nums.length; j++){
            if(list.contains(nums[j])){
                continue;
            }
            list.add(nums[j]);
            backTrace(nums, list);
            list.remove(list.size() - 1);
        }
    }
}
